package com.alibaba.citrus.cr.price.ability.functions.factory.price.process;

import com.alibaba.citrus.cr.common.annotation.RepositoryInvoker;
import com.alibaba.lattice2.epoch.sdk.model.Result;
import com.epoch.app.crplatformenhance.domain.scitemunit.dto.ScItemUnitLoadListRequest;
import com.epoch.app.crplatformenhance.domain.scitemunit.model.ScItemUnit;
import com.epoch.app.crplatformenhance.domain.scitemunit.service.ScItemUnitService;
import com.epoch.app.crpricecenter.enums.DimensionPropertyEnum;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author hanguo
 * @date 2021/11/19
 * @Description 销售单位
 */
@Component
public class SaleUnitProcess extends PriceProcess {

    @Resource
    private ScItemUnitService service;

    @Override
    @RepositoryInvoker
    public Map<String, String> obtainCodeAndDescMap(List<String> codeList, boolean innerCode) {
        if (CollectionUtils.isEmpty(codeList)) {
            return new HashMap<>();
        }
        Map<String, String> map = new HashMap<>();
        for (String code : codeList) {
            ScItemUnitLoadListRequest request = new ScItemUnitLoadListRequest();
            request.setOutCode(code);
            Result<List<ScItemUnit>> listResult = service.loadScItemUnitList(request);
            if (Objects.nonNull(listResult) && CollectionUtils.isNotEmpty(listResult.getResult())) {
                String name = listResult.getResult().get(0).getName();
                map.put(code, name);
            }
        }
        return map;
    }

    @Override
    @RepositoryInvoker
    public Map<String, String> obtainInnerCodeAndOuterCodeMap(List<String> codeList, boolean innerCode) {
        return new HashMap<>();
    }

    @Override
    public String getPropertyCode() {
        return DimensionPropertyEnum.SALES_UNIT_CODE.getKey();
    }
}
